<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty notice}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd"
				});
			});

			function validation(){
				try{
					if($(".dateFlag:checked").length == 0){
						if((document.frm.beginTime.value).replace(/\s/g, '') == ""){
							alert("[시작일]은 필수 입력 항목입니다.");
							document.frm.beginTime.focus();
							return false;
						}
						if((document.frm.endTime.value).replace(/\s/g, '') == ""){
							alert("[종료일]은 필수 입력 항목입니다.");
							document.frm.endTime.focus();
							return false;
						}
					}
					
					if($(".categoryIdx option:selected").val().replace(/\s/g, '') == "") {
						alert("[브랜드]은 필수 선택 항목입니다.");
						document.frm.categoryIdx.focus();
						return false;
					}
					
					if((document.frm.title.value).replace(/\s/g, '') == ""){
						alert("[제목]은 필수 입력 항목입니다.");
						document.frm.title.focus();
						return false;
					}
					
					if((document.frm.cont.value).replace(/\s/g, '') == ""){
						alert("[내용]은 필수 입력 항목입니다.");
						document.frm.cont.focus();
						return false;
					}
					
				}catch(err){
					return false;
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					공지사항 >  ${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/notice/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="searchBeginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="searchEndTime" value="${param.searchEndTime}" />
					<input type="hidden" name="idx" value="${notice.idx}">
					
					<table class="frmTbl">
						<colgroup>
							<col width="130px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<tr>
								<th>브랜드 *</th>
								<td>
									<select class="categoryIdx" name="categoryIdx">
										<option value="">선택</option>
										<c:forEach var="category" items="${categoryList}">
											<option value="${category.idx}" <c:if test="${notice.categoryIdx eq category.idx}"> selected="selected" </c:if>>${category.name}</option>
										</c:forEach>
									</select>
								</td>
							</tr>
							<tr>
								<th>기간 *</th>
								<td>
									<label>
										<input type="checkbox" class="dateFlag" <c:if test="${empty notice.beginTime && empty notice.endTime}"> checked="checked" </c:if> onclick="javascript:if(this.checked){$('.date').attr('disabled','disabled');}else{$('.date').removeAttr('disabled');};"> 항상
									</label>
									<c:catch var="e">
										<fmt:parseDate var="beginTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.beginTime}" />
										<fmt:formatDate var="beginTime" value="${beginTime}" pattern="yyyy-MM-dd" />
									</c:catch>
									<c:if test="${not empty e}">
										<c:set var="beginTime" value="${notice.beginTime}" />
									</c:if>
									<c:catch var="e">
										<fmt:parseDate var="endTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.endTime}" />
										<fmt:formatDate var="endTime" value="${endTime}" pattern="yyyy-MM-dd" />
									</c:catch>
									<c:if test="${not empty e}">
										<c:set var="endTime" value="${notice.endTime}" />
									</c:if>
									<input type="text" class="date" name="beginTime" <c:if test="${empty notice.beginTime && empty notice.endTime}"> disabled="disabled" </c:if> readonly="readonly" value="${beginTime}" />
									~
									<input type="text" class="date" name="endTime" <c:if test="${empty notice.beginTime && empty notice.endTime}"> disabled="disabled" </c:if> readonly="readonly" value="${endTime}" />
								</td>
							</tr>
							<tr>
								<th>제목 *</th>
								<td>
									<input type="text" name="title" value="${notice.title}" maxlength="50" style="width:660px;" />
								</td>
							</tr>
							<tr>
								<th>내용 *</th>
								<td>
									<textarea name="cont" maxlength="1000" style="width:660px;height: 150px;">${notice.cont}</textarea>
								</td>
							</tr>
							<!-- 
							<tr>
								<th>이미지 등록</th>
								<td style="line-height: 27px;padding:6px 0;">
									<input type="file" id="imgFile" name="imgFile" />
									<c:if test="${not empty notice.imgUrl}">
										<br /><img src="<c:out value="${notice.imgUrl}" />" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>
							<tr>
								<th>링크 url</th>
								<td>
									<input type="text" name="linkUrl" style="width:550px;" maxlength="200" value="<c:out value="${notice.linkUrl}" />" />
									<label><input type="radio" name="linkType" value="I" <c:if test="${notice.linkType eq 'I' or empty notice.linkType}"> checked="checked" </c:if>>내부</label>
									<label><input type="radio" name="linkType" value="O" <c:if test="${notice.linkType eq 'O'}"> checked="checked" </c:if>>외부</label>
								</td>
							</tr>
							 -->
						</tbody>
					</table>
					<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
					<input type="submit" class="btn" value="${fAct}" />
					<c:if test="${not empty notice}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('삭제 하시겠습니까?')){document.removeFrm.submit();}" />
					</c:if>
				</form>
				<form name="listFrm" action="<c:url value="/notice/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="beginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="endTime" value="${param.searchEndTime}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/notice/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${notice.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="beginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="endTime" value="${param.searchEndTime}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 